<?
/*
 * scrumbrella - Scrum board.
 *
 * Copyright (C) 2009  Gustavo N. Borgoni <gborgoni@voicemedia.com.ar>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

require_once("layout_config.php");
require_once("PHPTAL.php");

include("include/permission.php");
include("include/project.php");
include("layout_config.php");

// Check for user logged in
$user_id = permission_redirect_user("index.php");

	// Set the current tab
	$_SESSION['selected'] = 1;

	// Load the template
	$temp = new PHPTAL('templates/projects.xhtml');

	$temp->theme = 'default';
	$temp->title = _("Project list");
	$temp->project  = _("Project name");
	$temp->sprint   = _("Sprints");
	$temp->resource = _("Resources");
	$temp->role     = _("Your Role");
	$temp->backlog  = _("Project backlogs");
	$temp->progress = _("Progress");
	$temp->msg	= 0;

	$projects = project_list_byuser($user_id);
	if (!$projects) {
		$temp->projects = 0;
		$temp->msg      = 1;
		$temp->message  = _("You have not project asigned");
	} else {
		$i=0;
		foreach ($projects AS $project) {
			if ($class == 'project_item_cebra') {
				$class = 'project_item';
			} else {
				$class = 'project_item_cebra';
			}

			$prj[$i]['class']	= $class;
			$prj[$i]['name'] 	= $project['name'];
			$prj[$i]['id_project']	= $project['id_project'];
			$prj[$i]['sprint'] 	= count(project_get_lastsprint($project["id_project"]));
			$prj[$i]['member']	= count(project_get_members($project["id_project"], "Team Member"));
			$prj[$i]['role']	= permission_role_byid($project["id_role"]);
			$prj[$i]['pbacklog']	= project_backlogs_total($project["id_project"]);
			$prj[$i]['progress']	= project_progress($project["id_project"]);
			$prj[$i]['id_progress'] = "progressbar_".$project['id_project'];
			$i++;
		}
		$temp->projects = $prj;
	}

	try 
	{
		echo $temp->execute();
	}

	catch(Exception $e)
	{
		echo $e;
	}
?>
